﻿<UserControl x:Class="Chem4Word.UI.ManageView.LabelItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Chem4Word.UI.WebServices" Height="25" MouseLeftButtonDown="mouseLeftButtonDown" MouseLeftButtonUp="mouseLeftButtonUp" Margin="1,1,1,1" Name="labelItem" Padding=".5">
	<UserControl.DataContext>
		<Binding ElementName="labelItem" Path="." />
	</UserControl.DataContext>
	<UserControl.Resources>
		<local:EditingToVisibilityConverter x:Key="EditingToVisibilityConverter" />
		<Style x:Key="EntryFieldStyle" TargetType="Grid">
			<Setter Property="HorizontalAlignment" Value="Stretch" />
			<Setter Property="VerticalAlignment" Value="Center" />
			<Setter Property="Margin" Value="20,0" />
		</Style>

		<Style TargetType="{x:Type TextBox}">
			<Setter Property="BorderThickness" Value="0" />
			<Setter Property="Margin" Value="3,0" />
			<Setter Property="FontWeight" Value="Normal" />
			<EventSetter Event="GotKeyboardFocus" Handler="TextBoxGotFocus" />
			<Setter Property="Visibility" Value="Collapsed" />
			<EventSetter Event="LostKeyboardFocus" Handler="TextBoxLostFocus" />
			<Style.Triggers>
				<DataTrigger Binding="{Binding ElementName=LabelMoleculeBold, Path=IsSelected}" Value="True">
					<Setter Property="FontWeight" Value="Bold" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Path=Editing}" Value="True">
					<Setter Property="BorderThickness" Value="1" />
					<Setter Property="Visibility" Value="Visible" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style TargetType="{x:Type Button}">
			<Setter Property="IsEnabled" Value="True" />
			<Setter Property="Opacity" Value="1" />
			<Setter Property="Focusable" Value="False" />
			<Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
			<Setter Property="ToolTip" Value="Removes this item from the list of possible depictions for this chemical object." />
			<Style.Triggers>
				<DataTrigger Binding="{Binding Path=InUse}" Value="True">
					<Setter Property="IsEnabled" Value="False" />
					<Setter Property="Opacity" Value="0.5" />
					<Setter Property="ToolTip" Value="Cannot remove this item because it is in use in the document." />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style TargetType="{x:Type ComboBox}">
			<Setter Property="Opacity" Value="0.4" />
			<Setter Property="Focusable" Value="False" />
			<Style.Triggers>
				<Trigger Property="IsMouseOver" Value="True">
					<Setter Property="Opacity" Value="1"></Setter>
				</Trigger>
				<DataTrigger Binding="{Binding Path=Editing}" Value="True">
					<Setter Property="Opacity" Value="1" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style TargetType="{x:Type Border}">
			<Setter Property="BorderBrush" Value="{DynamicResource validEntryBrush}" />
			<Setter Property="BorderThickness" Value="{DynamicResource validEntryThickness}" />
			<Style.Triggers>
				<DataTrigger Binding="{Binding Path=IsValid}" Value="False">
					<Setter Property="BorderBrush" Value="{DynamicResource invalidEntryBrush}" />
					<Setter Property="BorderThickness" Value="{DynamicResource invalidEntryThickness}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>
		<Style x:Key="validStateImageStyle" TargetType="{x:Type Image}">
			<Setter Property="Stretch" Value="Uniform" />
			<Setter Property="Visibility" Value="Visible" />
			<Style.Triggers>
				<DataTrigger Binding="{Binding Path=IsValid}" Value="False">
					<Setter Property="Visibility" Value="Hidden" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Path=IsOutdated}" Value="True">
					<Setter Property="Visibility" Value="Hidden" />
				</DataTrigger>
			</Style.Triggers>
		</Style>
		<Style x:Key="warningStateImageStyle" TargetType="{x:Type Image}">
			<Setter Property="Stretch" Value="Uniform" />
			<Setter Property="Visibility" Value="Hidden" />
			<Style.Triggers>
				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding Path=IsOutdated}" Value="True" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Visibility" Value="Visible" />
				</MultiDataTrigger>
			</Style.Triggers>
		</Style>
		<Style x:Key="invalidStateImageStyle" TargetType="{x:Type Image}">
			<Setter Property="Stretch" Value="Uniform" />
			<Setter Property="Visibility" Value="Hidden" />
			<Style.Triggers>
				<DataTrigger Binding="{Binding Path=IsValid}" Value="False">
					<Setter Property="Visibility" Value="Visible" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style x:Key="stateLabelStyle" TargetType="{x:Type Label}">
			<Setter Property="Content" Value="Valid" />
			<Setter Property="Foreground" Value="Green" />
			<Style.Triggers>

				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding Path=IsOutdated}" Value="False" />
						<Condition Binding="{Binding Path=IsValid}" Value="False" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Content" Value="Not valid" />
					<Setter Property="Foreground" Value="Red" />
				</MultiDataTrigger>

				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding Path=IsOutdated}" Value="False" />
						<Condition Binding="{Binding Path=IsValid}" Value="True" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Content" Value="Valid" />
					<Setter Property="Foreground" Value="Green" />
				</MultiDataTrigger>

				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding Path=IsOutdated}" Value="True" />
						<Condition Binding="{Binding Path=IsValid}" Value="False" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Content" Value="Not valid" />
					<Setter Property="Foreground" Value="Red" />
				</MultiDataTrigger>

				<MultiDataTrigger>
					<MultiDataTrigger.Conditions>
						<Condition Binding="{Binding Path=IsOutdated}" Value="True" />
						<Condition Binding="{Binding Path=IsValid}" Value="True" />
					</MultiDataTrigger.Conditions>
					<Setter Property="Content" Value="Outdated" />
					<Setter Property="Foreground" Value="Orange" />
				</MultiDataTrigger>

			</Style.Triggers>
		</Style>

	</UserControl.Resources>
	<Border>
		<Grid>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="400*" />
				<ColumnDefinition Width="200" />
				<ColumnDefinition Width="85" />
				<ColumnDefinition Width="22" />
			</Grid.ColumnDefinitions>

			<Grid Grid.Column="0" Style="{StaticResource EntryFieldStyle}">
				<Grid.ToolTip>
					Enter or edit a label
				</Grid.ToolTip>
				<TextBlock Name="textBlock" FontSize="15" Margin="5,2">
					<TextBlock.Visibility>
						<MultiBinding Converter="{StaticResource EditingToVisibilityConverter}">
							<Binding ElementName="labelItem" Path="Editing" />
						</MultiBinding>
					</TextBlock.Visibility>
				</TextBlock>
				<TextBox Name="textBox" TextAlignment="Left" VerticalAlignment="Center" KeyUp="txtEditLabel_KeyUp" Background="Transparent">
					<TextBox.Text>
						<Binding Path="LabelText" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" />
					</TextBox.Text>
				</TextBox>
			</Grid>
			<ComboBox Grid.Column="1" x:Name="comboBox" HorizontalContentAlignment="Center" SelectionChanged="ComboBoxSelectionChanged">
				<ComboBoxItem x:Name="Prompt">Choose label type</ComboBoxItem>
				<ComboBoxItem x:Name="FormulaInline">Inline formula</ComboBoxItem>
				<ComboBoxItem x:Name="LabelMoleculeBold">
					Label - molecule bold number
				</ComboBoxItem>
				<ComboBoxItem x:Name="NameIupac">Name - IUPAC</ComboBoxItem>
				<ComboBoxItem x:Name="NameSystematic">Name - systematic</ComboBoxItem>
				<ComboBoxItem x:Name="NameAbbreviation">Name - abbreviation</ComboBoxItem>
				<ComboBoxItem x:Name="NameCas">Name - CAS</ComboBoxItem>
				<ComboBoxItem x:Name="NameTrivial">Name - trivial</ComboBoxItem>
                <ComboBoxItem x:Name="NameInchiKey">Name - InchiKey</ComboBoxItem>
                <ComboBoxItem x:Name="NameChemspider">Name - ChemSpider</ComboBoxItem>
                <ComboBoxItem x:Name="NameUnknown">Name - unknown</ComboBoxItem>
			</ComboBox>
			<Grid Grid.Column="2" x:Name="state">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="22" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Image x:Name="warningStateImage" Grid.Column="0" Style="{StaticResource warningStateImageStyle}" Source="../Resources/Images/Warning.png" />
				<Image x:Name="invalidStateImage" Grid.Column="0" Style="{StaticResource invalidStateImageStyle}" Source="../Resources/Images/Error.png" />
				<Image x:Name="validStateImage" Grid.Column="0" Style="{StaticResource validStateImageStyle}" Source="../Resources/Images/Apply.png" />
				<Label x:Name="stateLabel" Grid.Column="1" Style="{StaticResource stateLabelStyle}" />
			</Grid>
			<Button Click="BtnDeleteClick" Grid.Column="3">
				<Image Source="../Resources/Images/Delete.png" Stretch="Uniform" />
			</Button>
		</Grid>
	</Border>
</UserControl>